package com.sp.system.user.core.security.handler;

import com.sp.system.user.core.utils.ResponseUtil;
import com.sp.system.user.core.utils.enums.MenuEnum;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description: 权限不足处理类
 *               自定义权限不足需要做的业务操作
 *               包括：处理权限不足的逻辑
 * @Author: chenanhai
 * @Date: 2019年9月3日
 */
@Component
public class MyAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException e) throws IOException, ServletException {
//        log.error("权限不足，无法访问该资源",e);
        ResponseUtil.out(response, ResponseUtil.resultMap(MenuEnum.MENU_ERROR.getStatus(),e.getMessage()));
    }
}
